package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.Category;
import com.spzx.product.mapper.CategoryMapper;
import com.spzx.product.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper , Category> implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> treeSelect(Long id) {
        //查询pid到的下一级分类集合
       /* List<Category> categoryList = categoryMapper.selectList(new LambdaQueryWrapper<Category>().eq(Category::getParentId, parentId));
        if (!CollectionUtils.isEmpty(categoryList)){
            categoryList.forEach(item );
        }*/

        //查询pid到的下一级分类集合
        List<Category> categories = this.list(Wrappers.lambdaQuery(Category.class)
                .eq(Category::getParentId, id)
                .orderByDesc(Category::getOrderNum));

        //遍历查询每个分类是否有下一级
        if(!CollectionUtils.isEmpty(categories)){
            categories.forEach(category -> {
                long count = this.count(Wrappers.lambdaQuery(Category.class)
                        .eq(Category::getParentId, category.getId()));
            });
        }

        return categories;

    }

    @Override
    public String selectCategoryIdsByC3Id(Long category3Id) {
        return baseMapper.selectCategoryIdsByC3Id(category3Id);
    }

    @Override
    public List<Long> getAllCategoryIdList(Long categoryId) {
        return null;
    }

   /* @Override
    public List<Long> getAllCategoryIdList(Long categoryId) {
        return baseMapper.getAllCategoryIdList;
    }*/
}
